/*
 * @Author: 陈国庆 2306727047@qq.com
 * @Date: 2023-12-09 11:00:53
 * @LastEditors: 陈国庆 2306727047@qq.com
 * @LastEditTime: 2023-12-12 11:04:32
 * @FilePath: \boke7.0\boke-server\src\user\user.controller.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { Controller, Get, Req, Query } from '@nestjs/common';
import { UserService } from './user.service';
import { Request } from 'express';
import { Res } from 'src/utils/Res';

@Controller()
export class UserController {
  constructor(private readonly appService: UserService) {}

  @Get('/app')
  Hello() {
    return this.appService.findAll();
  }

  @Get('/login')
  async Go(@Query() query: Request['query']) {
    const { username, password } = query as {
      username: string;
      password: string;
    };
    const res = await this.appService.findUsername(username);
    if (res) {
      if (res.password == password) {
        return Res({
          ...res,
          msg: '登录成功！',
          token: 'dgfhsjjjcjfjvhfhf',
        });
      } else {
        return Res(
          {
            msg: '登录失败！',
            token: null,
          },
          'error',
        );
      }
    } else {
      return Res({
        msg:'没有用户！！'
      },'error');
    }
  }
}
